home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / emacssrc.zip / EMACSSRC.TAR / emacs-19.17 / src / scroll.c < prev    next >
C/C++ Source or Header  |  1993-10-07  |  21KB  |  628 lines

  1. /* Calculate what line insertion or deletion to do, and do it,
  2.    Copyright (C) 1985, 1986, 1990, 1993 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include "config.h"
  22. #include "termchar.h"
  23. #include "lisp.h"
  24. #include "dispextern.h"
  25. #include "frame.h"
  26. #ifdef STDC_HEADERS
  27. #include <stdlib.h>
  28. #endif
  29.  
  30. extern struct display_line **ophys_lines;
  31.  
  32. #ifndef max
  33. #define max(a, b) ((a) > (b) ? (a) : (b))
  34. #endif
  35. #ifndef min
  36. #define min(a, b) ((a) < (b) ? (a) : (b))
  37. #endif
  38.  
  39. /* All costs measured in characters.
  40.    So no cost can exceed the area of a frame, measured in characters.
  41.    Let's hope this is never more than 15000 characters.  */
  42.  
  43. #define INFINITY 15000
  44.  
  45. struct matrix_elt
  46.   {
  47.     /* Cost of outputting through this line
  48.        if no insert/delete is done just above it.  */
  49.     short writecost;
  50.     /* Cost of outputting through this line
  51.        if an insert is done just above it.  */
  52.     short insertcost;
  53.     /* Cost of outputting through this line
  54.        if a delete is done just above it.  */
  55.     short deletecost;
  56.     /* Number of inserts so far in this run of inserts,
  57.        for the cost in insertcost.  */
  58.     char insertcount;
  59.     /* Number of deletes so far in this run of deletes,
  60.        for the cost in deletecost.  */
  61.     char deletecount;
  62.   };
  63.  
  64. #include "scroll_p.h"
  65. #include "alloca_p.h"
  66. #include "term_p.h"
  67. static _VOID_ calculate_scrolling _P_((FRAME_PTR frame,
  68.                                        struct matrix_elt *matrix,
  69.                                        int window_size, int lines_below,
  70.                                        int *draw_cost, int *old_hash,
  71.                                        int *new_hash, int free_at_end));
  72. static _VOID_ do_scrolling _P_((FRAME_PTR frame, struct matrix_elt *matrix,
  73.                                 int window_size, int unchanged_at_top));
  74. static _VOID_ line_ins_del _P_((FRAME_PTR frame, int ov1, int pf1, int ovn,
  75.                                 int pfn, register int *ov,
  76.                                 register int *mf));
  77. static _VOID_ ins_del_costs _P_((FRAME_PTR frame, char *one_line_string,
  78.                                  char *multi_string, char *setup_string,
  79.                                  char *cleanup_string, int *costvec,
  80.                                  int *ncostvec, int coefficient));
  81.  
  82.  
  83. /* Determine, in matrix[i,j], the cost of updating the first j old lines
  84.    into the first i new lines.
  85.    This involves using insert or delete somewhere if i != j.
  86.    For each matrix elements, three kinds of costs are recorded:
  87.    the smallest cost that ends with an insert, the smallest
  88.    cost that ends with a delete, and the smallest cost that
  89.    ends with neither one.  These are kept separate because
  90.    on some terminals the cost of doing an insert varies
  91.    depending on whether one was just done, etc.  */
  92.  
  93. /* draw_cost[VPOS] is the cost of outputting new line at VPOS.
  94.    old_hash[VPOS] is the hash code of the old line at VPOS.
  95.    new_hash[VPOS] is the hash code of the new line at VPOS.
  96.    Note that these are not true frame vpos's, but relative
  97.    to the place at which the first mismatch between old and
  98.    new contents appears.  */
  99.  
  100. static void
  101. calculate_scrolling (frame, matrix, window_size, lines_below,
  102.              draw_cost, old_hash, new_hash,
  103.              free_at_end)
  104.      FRAME_PTR frame;
  105.      /* matrix is of size window_size + 1 on each side.  */
  106.      struct matrix_elt *matrix;
  107.      int window_size;
  108.      int lines_below;
  109.      int *draw_cost;
  110.      int *old_hash;
  111.      int *new_hash;
  112.      int free_at_end;
  113. {
  114.   register int i, j;
  115.   int frame_height = FRAME_HEIGHT (frame);
  116.   register struct matrix_elt *p, *p1;
  117.   register int cost, cost1;
  118.  
  119.   int lines_moved = window_size + (scroll_region_ok ? 0 : lines_below);
  120.   /* first_insert_cost[I] is the cost of doing the first insert-line
  121.      at the I'th line of the lines we are considering,
  122.      where I is origin 1 (as it is below).  */
  123.   int *first_insert_cost
  124.     = &FRAME_INSERT_COST (frame)[frame_height - 1 - lines_moved];
  125.   int *first_delete_cost
  126.     = &FRAME_DELETE_COST (frame)[frame_height - 1 - lines_moved];
  127.   int *next_insert_cost
  128.     = &FRAME_INSERTN_COST (frame)[frame_height - 1 - lines_moved];
  129.   int *next_delete_cost
  130.     = &FRAME_DELETEN_COST (frame)[frame_height - 1 - lines_moved];
  131.  
  132.   /* Discourage long scrolls on fast lines.
  133.      Don't scroll nearly a full frame height unless it saves
  134.      at least 1/4 second.  */
  135.   int extra_cost = baud_rate / (10 * 4 * FRAME_HEIGHT (frame));
  136.  
  137.   if (baud_rate <= 0)
  138.     extra_cost = 1;
  139.  
  140.   /* initialize the top left corner of the matrix */
  141.   matrix->writecost = 0;
  142.   matrix->insertcost = INFINITY;
  143.   matrix->deletecost = INFINITY;
  144.   matrix->insertcount = 0;
  145.   matrix->deletecount = 0;
  146.  
  147.   /* initialize the left edge of the matrix */
  148.   cost = first_insert_cost[1] - next_insert_cost[1];
  149.   for (i = 1; i <= window_size; i++)
  150.     {
  151.       p = matrix + i * (window_size + 1);
  152.       cost += draw_cost[i] + next_insert_cost[i] + extra_cost;
  153.       p->insertcost = cost;
  154.       p->writecost = INFINITY;
  155.       p->deletecost = INFINITY;
  156.       p->insertcount = i;
  157.       p->deletecount = 0;
  158.     }
  159.  
  160.   /* initialize the top edge of the matrix */
  161.   cost = first_delete_cost[1] - next_delete_cost[1];
  162.   for (j = 1; j <= window_size; j++)
  163.     {
  164.       cost += next_delete_cost[j];
  165.       matrix[j].deletecost = cost;
  166.       matrix[j].writecost = INFINITY;
  167.       matrix[j].insertcost = INFINITY;
  168.       matrix[j].deletecount = j;
  169.       matrix[j].insertcount = 0;
  170.     }
  171.  
  172.   /* `i' represents the vpos among new frame contents.
  173.      `j' represents the vpos among the old frame contents.  */
  174.   p = matrix + window_size + 2;    /* matrix [1, 1] */
  175.   for (i = 1; i <= window_size; i++, p++)
  176.     for (j = 1; j <= window_size; j++, p++)
  177.       {
  178.     /* p contains the address of matrix [i, j] */
  179.  
  180.     /* First calculate the cost assuming we do
  181.        not insert or delete above this line.
  182.        That is, if we update through line i-1
  183.        based on old lines through j-1,
  184.        and then just change old line j to new line i.  */
  185.     p1 = p - window_size - 2; /* matrix [i-1, j-1] */
  186.     cost = p1->writecost;
  187.     if (cost > p1->insertcost)
  188.       cost = p1->insertcost;
  189.     if (cost > p1->deletecost)
  190.       cost = p1->deletecost;
  191.     if (old_hash[j] != new_hash[i])
  192.       cost += draw_cost[i];
  193.     p->writecost = cost;
  194.  
  195.     /* Calculate the cost if we do an insert-line
  196.        before outputting this line.
  197.        That is, we update through line i-1
  198.        based on old lines through j,
  199.        do an insert-line on line i,
  200.        and then output line i from scratch,
  201.        leaving old lines starting from j for reuse below.  */
  202.     p1 = p - window_size - 1; /* matrix [i-1, j] */
  203.     /* No need to think about doing a delete followed
  204.        immediately by an insert.  It cannot be as good
  205.        as not doing either of them.  */
  206.     if (free_at_end == i)
  207.       {
  208.         cost = p1->writecost;
  209.         cost1 = p1->insertcost;
  210.       }
  211.     else
  212.       {
  213.         cost = p1->writecost + first_insert_cost[i];
  214.         if (p1->insertcount > i)
  215.           abort ();
  216.         cost1 = p1->insertcost + next_insert_cost[i - p1->insertcount];
  217.       }
  218.     p->insertcost = min (cost, cost1) + draw_cost[i] + extra_cost;
  219.     p->insertcount = (cost < cost1) ? 1 : p1->insertcount + 1;
  220.     if (p->insertcount > i)
  221.       abort ();
  222.  
  223.     /* Calculate the cost if we do a delete line after
  224.        outputting this line.
  225.        That is, we update through line i
  226.        based on old lines through j-1,
  227.        and throw away old line j.  */
  228.     p1 = p - 1;        /* matrix [i, j-1] */
  229.     /* No need to think about doing an insert followed
  230.        immediately by a delete.  */
  231.     if (free_at_end == i)
  232.       {
  233.         cost = p1->writecost;
  234.         cost1 = p1->deletecost;
  235.       }
  236.     else
  237.       {
  238.         cost = p1->writecost + first_delete_cost[i];
  239.         cost1 = p1->deletecost + next_delete_cost[i];
  240.       }
  241.     p->deletecost = min (cost, cost1);
  242.     p->deletecount = (cost < cost1) ? 1 : p1->deletecount + 1;
  243.       }
  244. }
  245.  
  246. /* Perform insert-lines and delete-lines operations
  247.  according to the costs in the matrix.
  248.  Updates the contents of the frame to record what was done. */
  249.  
  250. static void
  251. do_scrolling (frame, matrix, window_size, unchanged_at_top)
  252.      FRAME_PTR frame;
  253.      struct matrix_elt *matrix;
  254.      int window_size;
  255.      int unchanged_at_top;
  256. {
  257.   register struct matrix_elt *p;
  258.   register int i, j;
  259.   register struct frame_glyphs *current_frame;
  260.   /* temp_frame->enable[i] means line i has been moved to current_frame.  */
  261.   register struct frame_glyphs *temp_frame;
  262.   struct queue { int count, pos; } *queue;
  263.   int offset = unchanged_at_top;
  264.   int qi = 0;
  265.   int window = 0;
  266.   register int tem;
  267.   int next;
  268.  
  269.   queue = (struct queue *) alloca (FRAME_HEIGHT (frame)
  270.                    * sizeof (struct queue));
  271.  
  272.   current_frame = FRAME_CURRENT_GLYPHS (frame);
  273.   temp_frame = FRAME_TEMP_GLYPHS (frame);
  274.  
  275.   bcopy (current_frame->glyphs, temp_frame->glyphs,
  276.      current_frame->height * sizeof (GLYPH *));
  277.   bcopy (current_frame->used, temp_frame->used,
  278.      current_frame->height * sizeof (int));
  279.   bcopy (current_frame->highlight, temp_frame->highlight,
  280.      current_frame->height * sizeof (char));
  281.   bzero (temp_frame->enable, temp_frame->height * sizeof (char));
  282.   bcopy (current_frame->bufp, temp_frame->bufp,
  283.      current_frame->height * sizeof (int));
  284.  
  285. #ifdef HAVE_X_WINDOWS
  286.   if (FRAME_X_P (frame))
  287.     {
  288.       bcopy (current_frame->top_left_x, temp_frame->top_left_x,
  289.          current_frame->height * sizeof (short));
  290.       bcopy (current_frame->top_left_y, temp_frame->top_left_y,
  291.          current_frame->height * sizeof (short));
  292.       bcopy (current_frame->pix_width, temp_frame->pix_width,
  293.          current_frame->height * sizeof (short));
  294.       bcopy (current_frame->pix_height, temp_frame->pix_height,
  295.          current_frame->height * sizeof (short));
  296.       bcopy (current_frame->max_ascent, temp_frame->max_ascent,
  297.          current_frame->height * sizeof (short));
  298.     }
  299. #endif
  300.  
  301.   i = j = window_size;
  302.  
  303.   while (i > 0 || j > 0)
  304.     {
  305.       p = matrix + i * (window_size + 1) + j;
  306.       tem = p->insertcost;
  307.       if (tem < p->writecost && tem < p->deletecost)
  308.     {
  309.       /* Insert should be done at vpos i-1, plus maybe some before */
  310.       queue[qi].count = p->insertcount;
  311.       i -= p->insertcount;
  312.       queue[qi++].pos = i + unchanged_at_top;
  313.     }
  314.       else if (p->deletecost < p->writecost)
  315.     {
  316.       /* Old line at vpos j-1, and maybe some before it,
  317.          should be deleted */
  318.       j -= p->deletecount;
  319.        if (!window)
  320.         {
  321.           set_terminal_window (window_size + unchanged_at_top);
  322.           window = 1;
  323.         }
  324.       ins_del_lines (j + unchanged_at_top, - p->deletecount);
  325.     }
  326.       else
  327.     {
  328.       /* Best thing done here is no insert or delete */
  329.       /* Old line at vpos j-1 ends up at vpos i-1 */
  330.       current_frame->glyphs[i + offset - 1]
  331.         = temp_frame->glyphs[j + offset - 1];
  332.       current_frame->used[i + offset - 1]
  333.         = temp_frame->used[j + offset - 1];
  334.       current_frame->highlight[i + offset - 1]
  335.         = temp_frame->highlight[j + offset - 1];
  336.  
  337.       temp_frame->enable[j + offset - 1] = 1;
  338.       i--;
  339.       j--;
  340.     }
  341.     }
  342.  
  343.   if (!window && qi)
  344.     {
  345.       set_terminal_window (window_size + unchanged_at_top);
  346.       window = 1;
  347.     }
  348.  
  349.   /* Now do all insertions */
  350.  
  351.   next = unchanged_at_top;
  352.   for (i = qi - 1; i >= 0; i--)
  353.     {
  354.       ins_del_lines (queue[i].pos, queue[i].count);
  355.  
  356.       /* Mark the inserted lines as clear,
  357.      and put into them the line-contents strings
  358.      that were discarded during the deletions.
  359.      Those are the ones for which temp_frame->enable was not set.  */
  360.       tem = queue[i].pos;
  361.       for (j = tem + queue[i].count - 1; j >= tem; j--)
  362.     {
  363.       current_frame->enable[j] = 0;
  364.       while (temp_frame->enable[next])
  365.         next++;
  366.       current_frame->glyphs[j] = temp_frame->glyphs[next++];
  367.     }
  368.     }
  369.  
  370.   if (window)
  371.     set_terminal_window (0);
  372. }
  373.  
  374. void
  375. scrolling_1 (frame, window_size, unchanged_at_top, unchanged_at_bottom,
  376.          draw_cost, old_hash, new_hash, free_at_end)
  377.      FRAME_PTR frame;
  378.      int window_size, unchanged_at_top, unchanged_at_bottom;
  379.      int *draw_cost;
  380.      int *old_hash;
  381.      int *new_hash;
  382.      int free_at_end;
  383. {
  384.   struct matrix_elt *matrix;
  385.   matrix = ((struct matrix_elt *)
  386.         alloca ((window_size + 1) * (window_size + 1) * sizeof *matrix));
  387.  
  388.   calculate_scrolling (frame, matrix, window_size, unchanged_at_bottom,
  389.                draw_cost, old_hash, new_hash,
  390.                free_at_end);
  391.   do_scrolling (frame, matrix, window_size, unchanged_at_top);
  392. }
  393.  
  394. /* Return number of lines in common between current and desired frame contents
  395.    described to us only as vectors of hash codes OLDHASH and NEWHASH.
  396.    Consider only vpos range START to END (not including END).
  397.    Ignore short lines on the assumption that
  398.    avoiding redrawing such a line will have little weight.  */
  399.  
  400. int
  401. scrolling_max_lines_saved (start, end, oldhash, newhash, cost)
  402.      int start, end;
  403.      int *oldhash, *newhash, *cost;
  404. {
  405.   struct { int hash; int count; } lines[01000];
  406.   register int i, h;
  407.   register int matchcount = 0;
  408.   int avg_length = 0;
  409.   int threshold;
  410.  
  411.   /* Compute a threshold which is 1/4 of average length of these lines.  */
  412.  
  413.   for (i = start; i < end; i++)
  414.     avg_length += cost[i];
  415.  
  416.   avg_length /= end - start;
  417.   threshold = avg_length / 4;
  418.  
  419.   bzero (lines, sizeof lines);
  420.  
  421.   /* Put new lines' hash codes in hash table.
  422.      Ignore lines shorter than the threshold.
  423.      Thus, if the lines that are in common
  424.      are mainly the ones that are short,
  425.      they won't count.  */
  426.   for (i = start; i < end; i++)
  427.     {
  428.       if (cost[i] > threshold)
  429.     {
  430.       h = newhash[i] & 0777;
  431.       lines[h].hash = newhash[i];
  432.       lines[h].count++;
  433.     }
  434.     }
  435.  
  436.   /* Look up old line hash codes in the hash table.
  437.      Count number of matches between old lines and new.  */
  438.  
  439.   for (i = start; i < end; i++)
  440.     {
  441.       h = oldhash[i] & 0777;
  442.       if (oldhash[i] == lines[h].hash)
  443.     {
  444.       matchcount++;
  445.       if (--lines[h].count == 0)
  446.         lines[h].hash = 0;
  447.     }
  448.     }
  449.  
  450.   return matchcount;
  451. }
  452.  
  453. /* Return a measure of the cost of moving the lines
  454.    starting with vpos FROM, up to but not including vpos TO,
  455.    down by AMOUNT lines (AMOUNT may be negative).
  456.    These are the same arguments that might be given to
  457.    scroll_frame_lines to perform this scrolling.  */
  458.  
  459. int
  460. scroll_cost (frame, from, to, amount)
  461.      FRAME_PTR frame;
  462.      int from, to, amount;
  463. {
  464.   /* Compute how many lines, at bottom of frame,
  465.      will not be involved in actual motion.  */
  466.   int limit = to;
  467.   int offset;
  468.   int height = FRAME_HEIGHT (frame);
  469.  
  470.   if (amount == 0)
  471.     return 0;
  472.  
  473.   if (! scroll_region_ok)
  474.     limit = height;
  475.   else if (amount > 0)
  476.     limit += amount;
  477.  
  478.   if (amount < 0)
  479.     {
  480.       int temp = to;
  481.       to = from + amount;
  482.       from = temp + amount;
  483.       amount = - amount;
  484.     }
  485.  
  486.   offset = height - limit;
  487.  
  488.   return
  489.     (FRAME_INSERT_COST (frame)[offset + from]
  490.      + (amount - 1) * FRAME_INSERTN_COST (frame)[offset + from]
  491.      + FRAME_DELETEN_COST (frame)[offset + to]
  492.      + (amount - 1) * FRAME_DELETE_COST (frame)[offset + to]);
  493. }
  494.  
  495. /* Calculate the line insertion/deletion
  496.    overhead and multiply factor values */
  497.  
  498. static void
  499. line_ins_del (frame, ov1, pf1, ovn, pfn, ov, mf)
  500.      FRAME_PTR frame;
  501.      int ov1, ovn;
  502.      int pf1, pfn;
  503.      register int *ov, *mf;
  504. {
  505.   register int i;
  506.   register int frame_height = FRAME_HEIGHT (frame);
  507.   register int insert_overhead = ov1 * 10;
  508.   register int next_insert_cost = ovn * 10;
  509.  
  510.   for (i = frame_height-1; i >= 0; i--)
  511.     {
  512.       mf[i] = next_insert_cost / 10;
  513.       next_insert_cost += pfn;
  514.       ov[i] = (insert_overhead + next_insert_cost) / 10;
  515.       insert_overhead += pf1;
  516.     }
  517. }
  518.  
  519. static void
  520. ins_del_costs (frame,
  521.            one_line_string, multi_string,
  522.            setup_string, cleanup_string,
  523.            costvec, ncostvec, coefficient)
  524.      FRAME_PTR frame;
  525.      char *one_line_string, *multi_string;
  526.      char *setup_string, *cleanup_string;
  527.      int *costvec, *ncostvec;
  528.      int coefficient;
  529. {
  530.   if (multi_string)
  531.     line_ins_del (frame,
  532.           string_cost (multi_string) * coefficient,
  533.           per_line_cost (multi_string) * coefficient,
  534.           0, 0, costvec, ncostvec);
  535.   else if (one_line_string)
  536.     line_ins_del (frame,
  537.           string_cost (setup_string) + string_cost (cleanup_string), 0,
  538.           string_cost (one_line_string),
  539.           per_line_cost (one_line_string),
  540.           costvec, ncostvec);
  541.   else
  542.     line_ins_del (frame,
  543.           9999, 0, 9999, 0,
  544.           costvec, ncostvec);
  545. }
  546.  
  547. /* Calculate the insert and delete line costs.
  548.    Note that this is done even when running with a window system
  549.    because we want to know how long scrolling takes (and avoid it).
  550.    This must be redone whenever the frame height changes.
  551.  
  552.    We keep the ID costs in a precomputed array based on the position
  553.    at which the I or D is performed.  Also, there are two kinds of ID
  554.    costs: the "once-only" and the "repeated".  This is to handle both
  555.    those terminals that are able to insert N lines at a time (once-
  556.    only) and those that must repeatedly insert one line.
  557.  
  558.    The cost to insert N lines at line L is
  559.            [tt.t_ILov  + (frame_height + 1 - L) * tt.t_ILpf] +
  560.     N * [tt.t_ILnov + (frame_height + 1 - L) * tt.t_ILnpf]
  561.  
  562.    ILov represents the basic insert line overhead.  ILpf is the padding
  563.    required to allow the terminal time to move a line: insertion at line
  564.    L changes (frame_height + 1 - L) lines.
  565.  
  566.    The first bracketed expression above is the overhead; the second is
  567.    the multiply factor.  Both are dependent only on the position at
  568.    which the insert is performed.  We store the overhead in
  569.    FRAME_INSERT_COST (frame) and the multiply factor in
  570.    FRAME_INSERTN_COST (frame).  Note however that any insertion
  571.    must include at least one multiply factor.  Rather than compute this
  572.    as FRAME_INSERT_COST (frame)[line]+FRAME_INSERTN_COST (frame)[line],
  573.    we add FRAME_INSERTN_COST (frame) into FRAME_INSERT_COST (frame).
  574.    This is reasonable because of the particular algorithm used in calcM.
  575.  
  576.    Deletion is essentially the same as insertion.
  577.  */
  578.  
  579. _VOID_
  580. do_line_insertion_deletion_costs (frame,
  581.                   ins_line_string, multi_ins_string,
  582.                   del_line_string, multi_del_string,
  583.                   setup_string, cleanup_string, coefficient)
  584.      FRAME_PTR frame;
  585.      char *ins_line_string, *multi_ins_string;
  586.      char *del_line_string, *multi_del_string;
  587.      char *setup_string, *cleanup_string;
  588.      int coefficient;
  589. {
  590.   if (FRAME_INSERT_COST (frame) != 0)
  591.     {
  592.       FRAME_INSERT_COST (frame) =
  593.     (int *) xrealloc (FRAME_INSERT_COST (frame),
  594.               FRAME_HEIGHT (frame) * sizeof (int));
  595.       FRAME_DELETEN_COST (frame) =
  596.     (int *) xrealloc (FRAME_DELETEN_COST (frame),
  597.               FRAME_HEIGHT (frame) * sizeof (int));
  598.       FRAME_INSERTN_COST (frame) =
  599.     (int *) xrealloc (FRAME_INSERTN_COST (frame),
  600.               FRAME_HEIGHT (frame) * sizeof (int));
  601.       FRAME_DELETE_COST (frame) =
  602.     (int *) xrealloc (FRAME_DELETE_COST (frame),
  603.               FRAME_HEIGHT (frame) * sizeof (int));
  604.     }
  605.   else
  606.     {
  607.       FRAME_INSERT_COST (frame) =
  608.     (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int));
  609.       FRAME_DELETEN_COST (frame) =
  610.     (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int));
  611.       FRAME_INSERTN_COST (frame) =
  612.     (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int));
  613.       FRAME_DELETE_COST (frame) = 
  614.     (int *) xmalloc (FRAME_HEIGHT (frame) * sizeof (int));
  615.     }
  616.  
  617.   ins_del_costs (frame,
  618.          ins_line_string, multi_ins_string,
  619.          setup_string, cleanup_string,
  620.          FRAME_INSERT_COST (frame), FRAME_INSERTN_COST (frame),
  621.          coefficient);
  622.   ins_del_costs (frame,
  623.          del_line_string, multi_del_string,
  624.          setup_string, cleanup_string,
  625.          FRAME_DELETEN_COST (frame), FRAME_DELETE_COST (frame),
  626.          coefficient);
  627. }
  628.